package org.jsserv.example.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class MainController extends AbstractController
{    
    private final static Node DATA=
        new Node("test", "Tree", null,
            new Node("books", "Books", null,
                new Node("b1", "Douglas Adams - Hitchhiker's Guide to the Galaxy", "http://en.wikipedia.org/wiki/The_Hitchhiker\'s_Guide_to_the_Galaxy"),
                new Node("b2", "Neal Stephenson - Diamond Age", "http://en.wikipedia.org/wiki/The_Diamond_Age"),
                new Node("b3", "Douglas Coupland - Microserfs", "http://en.wikipedia.org/wiki/Microserfs")                
            ),
            new Node("music", "Songs", null,
                new Node("mus1", "David Bowie - Space Oddity", "http://www.google.com/musics?lid=2dG8AgOSCvI&amp;aid=d1wLcsOrUO&amp;sid=kEjQJ5wD1C"),
                new Node("mus2", "Nick Drake - Fruit Tree", "http://www.google.com/musics?lid=jL9V5KN3W_H&amp;aid=AlZ3QiY2VnG&amp;sid=wVfG280TsFH")
            ),
            new Node("movies", "Movies", null,
                new Node("mov1", "Stanley Kubrick - 2001: A Space Odyssey", "http://us.imdb.com/title/tt0062622/"),
                new Node("mov2", "Michel Gondry - Eternal Sunshine of the spotless Mind", "http://us.imdb.com/title/tt0338013/"),
                new Node("mov3", "Sofia Coppola - Lost in Translation", "http://us.imdb.com/title/tt0335266/")
                )
            );
    
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception
    {                
        ModelAndView modelAndView = new ModelAndView("main");
        modelAndView.addObject("data", DATA);
        return modelAndView;
    }
}
